﻿<Window
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:Converters="clr-namespace:MContracts.Classes.Converters"
  xmlns:my="clr-namespace:MContracts.Controls"
  xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="MContracts.Controls.Dialogs.ActDesignerDialog" 
  DataContext="{Binding}" 
   Loaded="ActDesignerDialogLoadedHandler" Unloaded="ActDesignerUnloadedHandler" Title="{Binding DisplayName}" d:DesignHeight="571" d:DesignWidth="842">
    <Window.Resources>
        <Style x:Key="CaptionStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="FontWeight" Value="DemiBold" />
            <Setter Property="FontStretch" Value="SemiExpanded" />
            <Setter Property="FontSize" Value="14" />
        </Style>
        <Style x:Key="TitleStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="FontWeight" Value="DemiBold" />
            <Setter Property="FontStretch" Value="SemiExpanded" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Margin" Value="5,0,5,0"/>

        </Style>
		     <Style x:Key="ControlTitleStyle" TargetType="{x:Type Control}">
            <Setter Property="FontWeight" Value="DemiBold" />
            <Setter Property="FontStretch" Value="SemiExpanded" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Margin" Value="5,0,5,0"/>

        </Style>
        <Style x:Key="GroupTitleStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="FontWeight" Value="DemiBold" />
            <Setter Property="FontStretch" Value="SemiExpanded" />
            <Setter Property="Background" Value="DarkSlateBlue" />
            <Setter Property="Foreground" Value="WhiteSmoke" />
            <Setter Property="FontFamily" Value="Segoe UI Lighte" />
            <Setter Property="FontSize" Value="14" />
        </Style>

        <Style x:Key="ValueStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="FontWeight" Value="DemiBold" />

            <Setter Property="FontSize" Value="12" />
            <Setter Property="Foreground" Value="DimGray" />
    
        </Style>
		
		<Style x:Key="BigValueStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="FontWeight" Value="DemiBold" />

            <Setter Property="FontSize" Value="16" />
            <Setter Property="Foreground" Value="DimGray" />
    
        </Style>
        <Converters:StringShrederConverter x:Key="SubjectStringTrimmer" MaxLength="200" Shreding="InTheMiddle"/>
		<Converters:BoolToVisibilityConverter x:Key="VisibilityConverter" FalseVisibility="Visible" TrueVisibility="Collapsed" />
			<Converters:NdsalgorithmToVisibilityConverter x:Key="NdsVisibilityConvrter" />
		
		
    </Window.Resources>
    <DockPanel Margin="10,5,10,5" LastChildFill="True">
        <StackPanel DockPanel.Dock="Top" Margin="0,5,0,20" Orientation="Vertical">
            <Border Background="RosyBrown" HorizontalAlignment="Stretch" CornerRadius="2" Padding="3">
                <TextBlock Style="{StaticResource CaptionStyle}" Foreground="White" TextWrapping="WrapWithOverflow" TextAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0}, {1} {2}">
                        <Binding Path="CurrentContract" />
                        <Binding Path="CurrentSchedule.Worktype" />
                        <!--<Binding Path="ScheduleMeasure" />-->     
                          <!--<Binding Path="CurrentContract.Contracttype" />-->
                          <Binding Path="CurrentContract.Contractor" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
            </Border>
 		
		<StackPanel Margin="0,15,0,0" HorizontalAlignment="Stretch" Orientation="Horizontal">
     	  
                <TextBlock Style="{StaticResource TitleStyle}" VerticalAlignment="Center" Margin="3,0"><Run Text="№"/></TextBlock>
                <TextBox Width="57.537" Text="{Binding CurrentAct.Num, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Margin="3,0"/>
                <TextBlock  Style="{StaticResource TitleStyle}" VerticalAlignment="Center" Margin="3,0"><Run Text="Дата"/></TextBlock>
                <DatePicker MinWidth="100" SelectedDate="{Binding CurrentAct.Signdate, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Margin="3,0"/>
                <CheckBox Margin="2,0,10,0" IsChecked="{Binding CurrentAct.Issigned}"  Style="{StaticResource ControlTitleStyle}" Content="{Binding CurrentAct.Signedstring}"  VerticalAlignment="Center"/>
                <ComboBox Margin="2,0,3,0" ItemsSource="{Binding ActTypes}" SelectedItem="{Binding CurrentAct.Acttype}" ToolTip="Тип акта"/>
				<Button Command="{Binding ShowPaymentDocumentDialogCommand}" Content="Платёжные документы…" VerticalAlignment="Center" Margin="3,0"/>
			</StackPanel>
		
			<StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal" Margin="20,10,0,0">
				<StackPanel Orientation="Horizontal" Visibility="{Binding CurrentContract.IsNational, Converter={StaticResource VisibilityConverter}}">
				<DatePicker Margin="2,0,3,0" SelectedDate="{Binding CurrentAct.Ratedate}" ToolTip="Дата курса валюты" />
					<Button Command="{Binding QueryCurrencyRateCommand}" Content="ЦБР" Width="41.36"/>
				<TextBox Margin="5,0,3,0" Text="{Binding CurrentAct.Currencyrate, ConverterCulture=ru-ru, StringFormat=N2, ValidatesOnDataErrors=True}" Width="47.36" ToolTip="Курс валюты"/>
				</StackPanel>
				
                <TextBlock  Style="{StaticResource TitleStyle}" VerticalAlignment="Center" Margin="5,0,3,0"><Run Text="Всего"/></TextBlock>
                <TextBlock  Style="{StaticResource ValueStyle}" VerticalAlignment="Center" Text="{Binding Text, ElementName=textBlockTotalClosedAmount}"/>
                		<TextBlock Style="{StaticResource TitleStyle}" Text="{Binding ScheduleMeasure}" VerticalAlignment="Center"/>
				<TextBlock  Style="{StaticResource TitleStyle}" VerticalAlignment="Center" Margin="3,0,3,0"><Run Text="Аванс"/></TextBlock>
                <TextBox Text="{Binding Credited, ConverterCulture=ru-ru, StringFormat=N2, ValidatesOnExceptions=True}" Width="92.03" VerticalAlignment="Center" Margin="3,0"/>
				<Button Margin="2,0,0,0" ToolTip="Задать рекомендуемое значение аванса по договору" Command="{Binding SetRecomendedPrepaymentCommand}">Рекомендуемый</Button>
				<TextBlock Style="{StaticResource TitleStyle}" Text="{Binding NationalMeasure}" VerticalAlignment="Center"/>
                <TextBlock Style="{StaticResource TitleStyle}" VerticalAlignment="Center" >(</TextBlock>
				<TextBlock  Style="{StaticResource ValueStyle}" VerticalAlignment="Center" ToolTip="Остаток по перечислениям" Text="{Binding PrepaymentRests, ConverterCulture=ru-ru, StringFormat=N2}"/>
				<TextBlock Style="{StaticResource TitleStyle}" Text="{Binding NationalMeasure}" VerticalAlignment="Center"/>
				<TextBlock Style="{StaticResource TitleStyle}" VerticalAlignment="Center" >)</TextBlock>
                <TextBlock  Style="{StaticResource TitleStyle}" VerticalAlignment="Center" Margin="3,0,3,0"><Run Text="К перечислению"/></TextBlock>
                <TextBlock  Style="{StaticResource BigValueStyle}" Text="{Binding CurrentAct.Sumfortransfer, ConverterCulture=ru-ru, StringFormat=N2}" VerticalAlignment="Center"/>
                <TextBlock Style="{StaticResource TitleStyle}" Text="{Binding NationalMeasure}" VerticalAlignment="Center"/>
				<ComboBox Margin="2,0,3,0" ItemsSource="{Binding NdsAlgorithms}" SelectedItem="{Binding CurrentAct.Ndsalgorithm}" ToolTip="Тип расчёта НДС"/>
                
				
				<StackPanel Orientation="Horizontal" Visibility="{Binding CurrentAct.Ndsalgorithm, Converter={StaticResource NdsVisibilityConvrter}}">
				<ComboBox Margin="2,0,3,0" ItemsSource="{Binding Repository.Nds}" SelectedItem="{Binding CurrentAct.Nds}" ToolTip="НДС"/>
				<TextBlock Margin="3,0,0,0" VerticalAlignment="Center" Style="{StaticResource BigValueStyle}" Text="{Binding TransferMoneyModel.NdsValue, ConverterCulture=ru-ru, StringFormat=N2, Mode=OneWay}"></TextBlock>
				<TextBlock Style="{StaticResource TitleStyle}" Text="{Binding NationalMeasure}" VerticalAlignment="Center"/>
				</StackPanel>
			
			</StackPanel>
			
       </StackPanel>
		<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,0,10,5" >
                <telerik:RadDropDownButton Margin="0,0,50,0" Content="Печать акта">
                <telerik:RadDropDownButton.DropDownContent>
                    <ListBox ItemsSource="{Binding ActTemplates}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Button Content="{Binding}" Command="{Binding Path=DataContext.CreateActReportCommand, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                   
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        </ListBox>
                </telerik:RadDropDownButton.DropDownContent>
            </telerik:RadDropDownButton>
        
			
        	<Button Margin="0,0,10,0" Width="140" Click="Button_Click" Content="Сохранить и закрыть"/>
        	<Button Margin="0,0,10,0" Width="100" IsCancel="True" Content="Отмена"/>
			<Button  Width="110" Click="CreateNextActClickHandler">
				<StackPanel Orientation="Horizontal" Margin="0,0,2,0">
					<TextBlock>Создать новый</TextBlock>
					<CheckBox VerticalAlignment="Center" Margin="5,0,0,0" IsChecked="{Binding ActNumberAutoIncrement}" Click="AutoIncClicked" ToolTip="Автоинкремент номера акта"></CheckBox>
				</StackPanel>
				</Button>
        </StackPanel>
        <Grid Margin="0,5,0,0">
            <Grid.Resources>
                <DataTemplate x:Key="StageItemTemplate">

                    <Border Padding="5" BorderBrush="LightGray" BorderThickness="1" CornerRadius="5" Loaded="ListItemBorderLoaded">
                        <DockPanel>
                        <TextBlock Foreground="Chocolate" DockPanel.Dock="Left">
							  <TextBlock.Resources>
							    <Converters:StageMarginConverter x:Key="StageMargin" />
							  </TextBlock.Resources>
                        	<TextBlock.Style>
                        		<StaticResource ResourceKey="TitleStyle"/>
                        	</TextBlock.Style>
								<TextBlock.Text>
							  <MultiBinding StringFormat="{}{0}.">
								 
								  <Binding Converter="{StaticResource StageMargin}" Path="Num" /> 
								  </MultiBinding>
									</TextBlock.Text>
                        </TextBlock>
                            <StackPanel>
                                <TextBlock Style="{StaticResource ValueStyle}" ToolTip="{Binding Subject}" TextWrapping="WrapWithOverflow">
						
								<TextBlock.Text>
							  <MultiBinding StringFormat="{}{0}.">

							    <Binding Path="Subject" Converter="{StaticResource SubjectStringTrimmer}" /> 
								  </MultiBinding>
									</TextBlock.Text>
                                </TextBlock>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Style="{StaticResource TitleStyle}"><Run Text="Без НДС"/></TextBlock>
                                    <TextBlock Text="{Binding StageMoneyModel.Factor.PureValue, ConverterCulture=ru-ru, StringFormat=N2}" Style="{StaticResource ValueStyle}"/>
                                    <TextBlock Style="{StaticResource TitleStyle}"><Run Text="НДС"/></TextBlock>
                                    <TextBlock Text="{Binding StageMoneyModel.Factor.NdsValue, ConverterCulture=ru-ru, StringFormat=N2, Mode=OneWay}" Style="{StaticResource ValueStyle}"/>
                                    <TextBlock Style="{StaticResource TitleStyle}"><Run Text="Включая НДС"/></TextBlock>
                                    <TextBlock Text="{Binding StageMoneyModel.Factor.PriceWithNdsValue, ConverterCulture=ru-ru, StringFormat=N2, Mode=OneWay}" Style="{StaticResource ValueStyle}"/>
                                </StackPanel>
                            </StackPanel>
                            </DockPanel>
                    </Border>

                </DataTemplate>

            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="40" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="*" />
                <RowDefinition Height="20" />
                <RowDefinition Height="70" />
            </Grid.RowDefinitions>
            <ListBox Grid.Row="1" HorizontalAlignment="Stretch" ItemsSource="{Binding OpenStages}" ItemTemplate="{StaticResource StageItemTemplate}" x:Name="listBoxOpnedStages" SelectionMode="Extended" VerticalAlignment="Stretch" MouseDoubleClick="OpenStageDoubleClick"/>
            <ListBox Grid.Column="2" Grid.Row="1" HorizontalAlignment="Stretch" ItemsSource="{Binding ClosedStages}" ItemTemplate="{StaticResource StageItemTemplate}" x:Name="listBoxClosedStages" SelectionMode="Extended" VerticalAlignment="Stretch" MouseDoubleClick="ClosedStageDoubleClick">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
            <TextBlock Style="{StaticResource GroupTitleStyle}" HorizontalAlignment="Stretch" x:Name="textBoxOpenedStages" TextAlignment="Center" VerticalAlignment="Stretch"  ToolTip="Показывает общее количество этапов и количество выбранных пользователем">
                      <TextBlock.Text>
						  <MultiBinding StringFormat="Открытые этапы ({0:D}/{1:D})">
<Binding Path="OpenStagesCount"/>
							  <Binding Path="SelectedOpenStagesCount"/>
							  </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock Style="{StaticResource GroupTitleStyle}" Grid.Column="2" HorizontalAlignment="Stretch" x:Name="textBoxClosedStages" TextAlignment="Center" VerticalAlignment="Stretch" ToolTip="Показывает общее количество этапов и количество выбранных пользователем">
                                  <TextBlock.Text>
  <MultiBinding StringFormat="Закрытые этапы ({0:D}/{1:D})">
<Binding Path="ClosedStagesCount"/>
							  <Binding Path="SelectedClosedStagesCount"/>
							  </MultiBinding>
                </TextBlock.Text>
            </TextBlock>

            <my:CommandsControl x:Name="commandsControl1" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
            <StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
                <TextBlock Style="{StaticResource TitleStyle}"><Run Text="Всего:"/></TextBlock>
                <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding OpenStageAmount, ConverterCulture=ru-ru, StringFormat=\{0:N2\}}"/>
                <TextBlock><Run Text=","/></TextBlock>
                <TextBlock Style="{StaticResource TitleStyle}" Text="{Binding ScheduleMeasure}"/>

            </StackPanel>
            <StackPanel Grid.Column="2" Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
                <TextBlock Style="{StaticResource TitleStyle}"><Run Text="Всего:"/></TextBlock>
                <TextBlock x:Name="textBlockTotalClosedAmount" Style="{StaticResource ValueStyle}" Text="{Binding ClosedStageAmount, ConverterCulture=ru-ru, StringFormat=\{0:N2\}}"/>
                <TextBlock><Run Text=","/></TextBlock>
                <TextBlock Style="{StaticResource TitleStyle}" Text="{Binding ScheduleMeasure}"/>

            </StackPanel>
            <StackPanel Grid.Column="2"  Grid.Row="3" HorizontalAlignment="Stretch">
            	
				<StackPanel Orientation="Horizontal">
            	<ComboBox ItemsSource="{Binding Regions}" Width="300" ToolTip="Регионы" SelectedItem="{Binding CurrentAct.Region}" HorizontalAlignment="Stretch"/>
				<Button Margin="5,0,5,0" ToolTip="Открыть редактор регионов" Content="&#x2026;" HorizontalAlignment="Right" Command="{Binding ShowRegionsEditor}"></Button>
				</StackPanel>
				
				<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
					<ComboBox Width="300" ItemsSource="{Binding Enterpriseauthorities}" HorizontalAlignment="Stretch" ToolTip="Основание" SelectedItem="{Binding CurrentAct.Enterpriseauthority}"/>
				<Button Margin="5,0,5,0"   Command="{Binding ShowEnterpriseAuthorityEditor}" ToolTip="Открыть редактор оснований" Content="&#x2026;"  HorizontalAlignment="Right"></Button>
					</StackPanel>
					
				</StackPanel>



        </Grid>
    </DockPanel>
</Window>